package com.colorful.insuranceproject.mine;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.colorful.insuranceproject.R;
import com.colorful.insuranceproject.base.TitleActivity;
import com.colorful.insuranceproject.bean.MessageContentBean;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by handsome-Bob on 2017/9/23.
 * <p>
 * 支付结果
 */
public class PaySuccessActivity extends TitleActivity {

    public static final String EXTRA_BEAN = "extra_bean";
    @Bind(R.id.img_result)
    ImageView imgResult;

    @Bind(R.id.tv_result_status)
    TextView tvResultStatus;

    @Bind(R.id.tv_result_money)
    TextView tvResultMoney;

    @Bind(R.id.tv_friendship_hint)
    TextView tvFriendshipHint;

    @Bind(R.id.ll_other_money)
    LinearLayout llOtherMoney;

    @Bind(R.id.tv_other_money)
    TextView tvOtherMoney;

    private MessageContentBean bean;

    @Override
    protected int getContentView() {
        return R.layout.activity_pay_success;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        setTitle(getString(R.string.pay_result));
    }

    @Override
    protected void onViewInitialized() {
        int type = bean.getType();
        if (type == 0) {// 取消
            tvResultStatus.setText(getString(R.string.pay_cancel));//支付状态
            tvResultMoney.setVisibility(View.GONE);//支付金额
            tvFriendshipHint.setText(getString(R.string.pay_again_hint));
        } else if (type == 1) {// 成功
            tvResultStatus.setText(getString(R.string.pay_success));//支付状态
            tvResultMoney.setText(getString(R.string.price_and_postmoney, bean.getKeKangAnPay()));//支付金额
            if (!bean.getOtherPay().equals("0") && !bean.getOtherPay().equals("0.0") && !bean.getOtherPay().equals("0.00")) {
                llOtherMoney.setVisibility(View.VISIBLE);
                tvOtherMoney.setText(getString(R.string.price_and_postmoney, bean.getOtherPay()));
            }
            tvFriendshipHint.setText(getString(R.string.friendShip_hint));
        } else if (type == 2) {// 异常
            imgResult.setImageResource(R.drawable.pay_exception_iocn);
            tvResultStatus.setText(getString(R.string.pay_exception));
            tvResultMoney.setVisibility(View.GONE);//money show
            tvFriendshipHint.setText(getString(R.string.pay_error_exception));
        }
    }

    @Override
    protected void onInitExtras(@NonNull Bundle bundle) {
        super.onInitExtras(bundle);
        bean = bundle.getParcelable(EXTRA_BEAN);
    }

    @Override
    public void restoreInstanceOnCreateBefore(@NonNull Bundle savedInstance) {

    }

    @Override
    public void restoreInstanceOnCreateAfter(@NonNull Bundle savedInstance) {

    }
}
